﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoMapper;
using DTO;

namespace DAO
{
    public class SanBay_DAO
    {
        public static SanBay_DTO CreateSanBayDTO(SanBay sanbay)
        {
            SanBay_DTO sanbayDTO = new SanBay_DTO();
            sanbayDTO.MaSanBay = sanbay.MaSanBay;
            sanbayDTO.TenSanBay = sanbay.TenSanBay;
            return sanbayDTO;
        }
        public List<SanBay_DTO> GetSanBayList()
        {
            List<SanBay_DTO> listSanBay = new List<SanBay_DTO>();
            try
            {
                QLCBDataContext context = new QLCBDataContext();
                //QLCBEntities context = new QLCBEntities();
                var query = from sanbay in context.SanBays select sanbay;
                foreach (var sb in query)
                {
                    SanBay_DTO sanbayDTO = CreateSanBayDTO(sb);
                    listSanBay.Add(sanbayDTO);
                }
            }
            catch (System.Exception ex)
            {
                string str = ex.Message;
            }
            return listSanBay;
        }

        public SanBay_DTO GetSanBayDetails(string maSanBay)
        {
            SanBay_DTO sanbayDTO = new SanBay_DTO();
            try
            {
                QLCBDataContext context = new QLCBDataContext();
                //QLCBEntities context = new QLCBEntities();
                var query = from sb in context.SanBays
                            where sb.MaSanBay == maSanBay
                            select sb;
                SanBay sanbayEF = query.First();
                sanbayDTO = CreateSanBayDTO(sanbayEF);
            }
            catch (System.Exception)
            {
            }
            return sanbayDTO;
        }

        public static string GetTenSanBay(string maMaSanBay)
        {
            QLCBDataContext context = new QLCBDataContext();
            string query = (from sb in context.SanBays
                                  where sb.MaSanBay == maMaSanBay
                                  select sb.TenSanBay).ToString();
            return query;
        }
       
    }
}
